

package com.hazelcast.jet.impl.operation;

import com.hazelcast.jet.config.DeltaJobConfig;
import com.hazelcast.jet.config.JobConfig;
import com.hazelcast.jet.impl.execution.init.JetInitDataSerializerHook;
import com.hazelcast.nio.ObjectDataInput;
import com.hazelcast.nio.ObjectDataOutput;

import java.io.IOException;
import java.util.concurrent.CompletableFuture;

public class UpdateJobConfigOperation extends AsyncJobOperation {
    private DeltaJobConfig deltaConfig;

    public UpdateJobConfigOperation() {
    }

    public UpdateJobConfigOperation(long jobId, DeltaJobConfig deltaConfig) {
        super(jobId);
        this.deltaConfig = deltaConfig;
    }

    @Override
    public CompletableFuture<JobConfig> doRun() {
        return getJobCoordinationService().updateJobConfig(jobId(), deltaConfig);
    }

    @Override
    public int getClassId() {
        return JetInitDataSerializerHook.UPDATE_JOB_CONFIG_OP;
    }

    @Override
    protected void writeInternal(ObjectDataOutput out) throws IOException {
        super.writeInternal(out);
        out.writeObject(deltaConfig);
    }

    @Override
    protected void readInternal(ObjectDataInput in) throws IOException {
        super.readInternal(in);
        deltaConfig = in.readObject();
    }
}
